import React, {Component} from 'react';
import Toast from 'react-native-root-toast'
import {InteractionManager} from "react-native";

/**
 * 文本提示框
 */
interface callBack {
    (): void
}
let toastInstance:Toast = null;
export default function toast(text: string, callback: callBack = () => {
}, duration: number = Toast.durations.SHORT, position: number = Toast.positions.CENTER) {
    if (text == null) return;
    if(toastInstance){
        hideToast(toastInstance);
    }
    toastInstance = Toast.show(text, {
        duration: duration,
        position: position,
        shadow: true,
        animation: true,
        hideOnPress: true,
        delay: 0,
    });
    setTimeout(callback,duration);
}

export function hideToast(toast) {
    Toast.hide(toast)
}